﻿using System;
using System.Collections.Generic;
using System.Web;
using Rabbit.Logic;
using RabbitShop.Code;

namespace RabbitShop.UI
{
    public partial class ProductDetail : System.Web.UI.Page
    {
        protected Product product = new Product();
        protected Shop shop = new Shop(){Location = new Address()};
        protected Address address=new Address();

        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request["id"];
            if (string.IsNullOrEmpty(id)) return;
            product = RabbitUse.GetProductById(Db.Store, id);

            string shopId = product.ShopId;
            if (string.IsNullOrEmpty(shopId)) return;

            shop = RabbitUse.GetShopByShopId(Db.Store, shopId);
            if (shop==null||shop.Location == null || shop.Location.Province == null)
            {
                shop = new Shop() { Location = new Address() };
            }

            HttpCookie cookie = Request.Cookies[Constant.CookieName];
            if (cookie == null || cookie.Values[Constant.CookieUprovince] == null || cookie.Values[Constant.CookieUcity] == null || cookie.Values[Constant.CookieUregion] == null)
            {
                address.Province = "北京";
                address.City = "北京市";
                address.Region = "东城区";
            }
            else
            {
                address.Province = HttpUtility.UrlDecode(cookie.Values[Constant.CookieUprovince]);
                address.City = HttpUtility.UrlDecode(cookie.Values[Constant.CookieUcity]);
                address.Region = HttpUtility.UrlDecode(cookie.Values[Constant.CookieUregion]);
            }

            //string uid = Request.Cookies[Constant.CookieName].Values[Constant.CookieUid];
            //if (!string.IsNullOrEmpty(uid))
            //{
            //    customer = RabbitUse.GetCustomerById(Db.Store, uid);
            //}
            //else
            //{
            //    customer = new Customer();
            //    customer.AddressList = new List<Address>() {new Address() {Province = "北京"}};
            //}

        }
    }
}